#include "myFunctions.h"

using namespace std;

/**
Lee de un archivo un patron para entrenamiento
*/
void readFile(vector<int> &X, string file){
	ifstream archi;
	archi.open(file.c_str());
	if(archi.is_open()){
		while(!archi.eof()){
			string str_line;
			char* line;
			getline(archi,str_line);
			line = &str_line[0];
			X.push_back(atoi(line));
		}
		X.pop_back();
		archi.close();
	}
}

//Funcion signo
int sign(double x){
	return ((fabs(x)-x) ? -1 : 1); 
}

double uniformDouble(){
	return ((double)rand() / ((double)(RAND_MAX)+(double)(1)));
}

vector<int> genTest(vector<int>& X,double probability){
	int l = X.size();
	vector<int> res;
	res.resize(l);
	for(int i=0;i<l;i++){
		double r = uniformDouble();
		if(r > probability)		
			res[i] = X[i];
		else
			res[i] = -1*X[i];
	}
	return res;
}

///----------------------------------------------------------------------------------///
///                          FUNCIONES ALGEBRAICAS                                   ///

/**
Resuelve el producto punto x.w = y
*/
double prod_punto(vector<double> &x, vector<int> &w){
	int l = x.size();
	double y = 0;	
	for(int i=0;i<l;i++){
		y += x[i]*w[i];		
	}
	return y;
}

void view_vi(vector<int>& v){
	for (unsigned int i=0;i<v.size();i++){
		cout<<v[i]<<" , ";	
	}
	cout<<endl;
}

void view_vd(vector<double>& v){
	for (unsigned int i=0;i<v.size();i++){
		cout<<v[i]<<" , ";	
	}
	cout<<endl;
}

